package com.mall.service.marketing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.PeekingIterator;
import com.mall.model.domain.SmsHomeNewProduct;
import com.mall.model.vo.PageResult;
import com.mall.service.marketing.mapper.SmsHomeNewProductMapper;
import com.mall.service.marketing.service.SmsHomeNewProductService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.PrimitiveIterator;

@Service
public class SmsHomeNewProductServiceImpl extends ServiceImpl<SmsHomeNewProductMapper, SmsHomeNewProduct> implements SmsHomeNewProductService{

    @Autowired
    private SmsHomeNewProductMapper smsHomeNewProductMapper;

    //分页查询首页新品
    @Override
    public PageResult findList(String productName, Integer recommendStatus, Integer pageNum, Integer pageSize) {
        Page<SmsHomeNewProduct> page = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<SmsHomeNewProduct> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(productName)){
            queryWrapper.like(SmsHomeNewProduct::getProductName,productName);
        }
        if (recommendStatus != null){
            queryWrapper.eq(SmsHomeNewProduct::getRecommendStatus,recommendStatus);
        }
        Page<SmsHomeNewProduct> shnpPage = smsHomeNewProductMapper.selectPage(page, queryWrapper);
        return new PageResult(pageNum,pageSize, (int) shnpPage.getTotal(),shnpPage.getRecords());

    }
}
